from django.shortcuts import render

from com.user.sign_in_controller import is_sign_in
from django.shortcuts import HttpResponseRedirect


class SignOut(object):
    def __init__(self, request):
        self.request = request

    def run(self):
        if is_sign_in(self.request)[0]:
            del self.request.session["user_name"]
            del self.request.session["user_id"]
            if self.request.session.get("terminal_id", None):
                del self.request.session["terminal_id"]
            if self.request.session.get("communicator_id", None):
                del self.request.session["communicator_id"]
            return HttpResponseRedirect("/")
        else:
            return render(self.request, "404.html", {})
